"use strict";
const path = require("path");
const { defineConfig } = require("@vue/cli-service");
const defaultSetting = require("./src/setting"); // 默认配置项

function resolve(dir) {
  return path.join(__dirname, dir);
}

const name = defaultSetting.title || "Vue Admin"; // page title

module.exports = defineConfig({
  lintOnSave: false,
  publicPath: "./",
  outputDir: "dist",
  assetsDir: "static",
  productionSourceMap: false,
  devServer: {
    https: false,
    port: 8080,
    open: false,
    proxy: {
      "/main": {
        target: "http://127.0.0.1:3540",
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          "^/main": "",
        },
      },
      "/test": {
        target: "http://127.0.0.1:8000",
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          "^/test": "",
        },
      },
    },
  },
  configureWebpack: {
    // provide the app's title in webpack's name field, so that
    // it can be accessed in index.html to inject the correct title.
    name: name,
    resolve: {
      alias: {
        "@": resolve("src"),
      },
    },
    module: {
      rules: [
        {
          test: require("path").resolve(__dirname, "node_modules/leader-line/"),
          use: [
            {
              loader: "skeleton-loader",
              options: {
                procedure: (content) => `${content}export default LeaderLine`,
              },
            },
          ],
        },
      ],
    },
  },

  chainWebpack(config) {
    // set svg-sprite-loader
    config.module.rule("svg").exclude.add(resolve("src/icons")).end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]",
      })
      .end();
  },
});
